import io.socket.emitter.Emitter;
import lombok.extern.slf4j.Slf4j;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketHttpHeaders;
import org.springframework.web.socket.WebSocketSession;
import io.socket.client.*;

import java.net.URI;
import java.nio.channels.NotYetConnectedException;

@Slf4j
@Component
/*
public class CustomWebSocketClient extends Socket {

    public CustomWebSocketClient(Manager io, String nsp, Manager.Options opts) {
        super(io, nsp, opts);
    }

    @Override
    public Socket open() {
        System.out.println("客户端连接成功");
        return super.open();
    }

    @Override
    public Socket connect() {
        System.out.println("客户端请求连接");
        return super.connect();
    }

    @Override
    public Socket send(Object... args) {
        System.out.println("客户端发送消息: " + args);
        return super.send(args);
    }

    @Override
    public Emitter emit(String event, Object... args) {
        return super.emit(event, args);
    }

    @Override
    public Emitter emit(String event, Object[] args, Ack ack) {
        return super.emit(event, args, ack);
    }

    @Override
    public Socket close() {
        System.out.println("客户端关闭连接");
        return super.close();
    }

    @Override
    public Socket disconnect() {
        return super.disconnect();
    }

    @Override
    public Manager io() {
        return super.io();
    }

    @Override
    public boolean connected() {
        return super.connected();
    }

    @Override
    public String id() {
        return super.id();
    }
}
 */


public class CustomWebSocketClient extends WebSocketClient {

    CustomWebSocketClient(URI uri) {
        super(uri);
    }

    @Override
    public void connect() {
        super.connect();
        System.out.println("客户端请求连接");
    }

    @Override
    public void send(String text) throws NotYetConnectedException {
        super.send(text);
        System.out.println("客户端发送消息: " + text);
    }

    @Override
    public void onOpen(ServerHandshake handshakedata) {
        System.out.println("客户端连接成功");

    }

    @Override
    public void onMessage(String message) {
        System.out.println("客户端收到消息: " + message);
    }

    @Override
    public void onClose(int code, String reason, boolean remote) {
        System.out.println("客户端关闭连接");
    }

    @Override
    public void onError(Exception ex) {
        System.out.println(ex);
    }
}
